#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

#define N 100005
int indeg[N];
vector<vector<int>> g(N);
int ans[N]; //记录当前点最大距离

int main()
{
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	//cout.tie(0);
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		indeg[y] += 1; //入度
		g[x].push_back(y);
	}
	queue<int> q;
	for (int i = 1; i <= n; i++)
	{
		if (indeg[i] == 0)
		{
			q.push(i);
			ans[i] = 1; //记录当前点
		}
	}
	while (!q.empty()) {
		int now = q.front();
		q.pop();
		for (int i = 0, I = g[now].size(); i < I; i++)
		{
			int t = g[now][i];
			indeg[t] -= 1;
			if (indeg[t] == 0) q.push(t);
			ans[t] = max(ans[now] + 1, ans[t]);
		}
	}

	for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);


	return 0;
}